package com.gopay.checkorder.common;

import java.util.Hashtable;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class BankLock {
    private final static Logger logger = LoggerFactory.getLogger("CHECK_ORDER");

    private static Hashtable<String, String> banks = new Hashtable<String, String>();

    public static boolean exist(String bankCode, String gopayOrderId) {
        if (banks.get(bankCode) != null) {
            logger.error("工行对单，已锁定 " + banks.get(bankCode));
            return true;
        } else {
            banks.put(bankCode, gopayOrderId);
            return false;
        }
    }

    public static void delete(String bankCode) {
        banks.remove(bankCode);
    }
    
    public static void delete(String bankCode, String orderId) {
        if (orderId != null && orderId.equals(banks.get(bankCode))) {
            banks.remove(bankCode); 
        }
    }
    
}
